package com.yvdelx.cyclowomen.activity.listener;

import android.app.Activity;
import android.content.Intent;
import android.view.View;

import com.yvdelx.R;
import com.yvdelx.cyclowomen.activity.CalendarActivity;
import com.yvdelx.cyclowomen.mediation.CycleManagement;
import com.yvdelx.cyclowomen.utility.ActivityUtility;
import com.yvdelx.cyclowomen.utility.LogUtility;
import com.yvdelx.cyclowomen.utility.ViewUtility;

/**
 * Listener for profile activity
 * Created by ydelvaux on 05/03/14.
 */
public class ProfileActivityListener extends AbstractActivityListener {


    public ProfileActivityListener(Activity act){
        this.activity = act;
    }

    @Override
    public void onClick(View view) {
        // Get name and first name user
        String name = ViewUtility.getStringEditText(this.activity.findViewById(R.id.NameEditText));
        String firstName = ViewUtility.getStringEditText(this.activity.findViewById(R.id.FirstnameEditText));

        try {
            // Create or modify profile
            CycleManagement.modifyProfile(name, firstName);
            // Go to calendar activity
            this.activity.startActivityForResult(new Intent(this.activity, CalendarActivity.class),
                    ActivityUtility.CST_CALENDAR_ACTIVITY);
        } catch (Exception e) {
            LogUtility.error(this.getClass(), e.getMessage(), e);
            this.activity.finish();
        }
    }
}
